<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
  </head>
  
  <body>

   <form id="formid" action="${pageContext.request.contextPath}/servlet/InfoServlet" method="post">
   <!-- 当前页 -->
   <input name = "currentPage" value="${currentPage}" id="currentPage" type="hidden"> 
   <!-- 数据总条数 -->
   <input name = "recordCount" value="${recordCount}" id="recordCount" type="hidden">
   <!-- 数据总页数 -->
   <input name = "pages" value="${pages}" id="pages" type="hidden"> 
   <!-- 排序列名 -->
   <input name = "sort" value="${sort}" id="sort" type="hidden"> 
   <!--  排序方法-->
   <input name = "type" value="${type}" id="type" type="hidden"> 
  
   
   船名：<input type="text" name="searchName" id="searchName">
   航次：<input type="text" name="searchVoyage" id="searchVoyage">
   货类：<input type="text" name="searchCategory" id="searchCategory">
   <button onclick="doSearch()">搜索</button>
   
   <table>
   <tr>
   <td  >编号</td>
   
   <td onclick="sortType(this)"  sort="SHIPNAME" type="DESC" >船名</td>
   <td onclick="sortType(this)"  sort="VOYAGE" type="DESC">航次</td>
   <td onclick="sortType(this)"  sort="CATEGORY" type="DESC">货类</td>
   <td>操作</td>
   </tr>
   <c:forEach var="shipInfo" items="${shipInfo}">
   <tr>
   
   <td>${shipInfo.PAGE_ROW_NUM}</td>
   <td>${shipInfo.SHIPNAME}</td>
   <td>${shipInfo.VOYAGE}</td>
   <td>${shipInfo.CATEGORY}</td>
   <td><a href="${pageContext.request.contextPath}/servlet/InfoServlet?method=edit&id=${shipInfo.ID}">编辑</a>
   	   <a href="${pageContext.request.contextPath}/servlet/InfoServlet?method=delete&id=${shipInfo.ID}">删除</a>
   </tr>
   </c:forEach>
   <a href="${pageContext.request.contextPath}/servlet/InfoServlet?method=add">新增</a>
   </table>
   </form>
     <!-- 分页 -->
	
             <div >
			   <a href="javascript:void(0)" onclick="changepage(1)">	首页</a>
			  
			   <a href="javascript:void(0)" onclick="changepage0()">上一页</a>
			    ${currentPage}  
			   <a href="javascript:void(0)" onclick="changepage1()"> 下一页   </a>
			   <a href="javascript:void(0)" onclick="changepage2()">	末页</a>  
			       跳转到 <input type="text" value="${currentPage}"  name="currentPage" id="index" style="size: 4px;text-align: center; ">页  
			  <input type="submit" onclick="changepage3()" value="确定">   共 ${recordCount}条数据
 			</div>
          

   <script type="text/javascript">
   
   function changepage(currentPage)
   {
   	var currentpage =currentPage ;
   	document.getElementById("currentPage").value=currentpage;
   	document.getElementById("formid").submit();
   }
   //前一页
    function changepage0()
   {
   	var currentpage = parseInt( document.getElementById("currentPage").value);
   	
   	if(currentpage==1)
   	{
   		alert("已经是第一页");
   	}
   	else
   	{
	   	currentpage =currentpage-1;
	   	document.getElementById("currentPage").value=currentpage;
	   	document.getElementById("formid").submit();
   	
   	}
   	
   }
   //后一页
    function changepage1()
   {
   	var currentpage = parseInt(document.getElementById("currentPage").value );
   	var pages = document.getElementById("pages").value;
   
   	if(currentpage==pages)
   	{
   	
   		alert("已经是最后一页")
   	}
   	else
   	{
   	
	    var	page =currentpage+1;
	   
	   	document.getElementById("currentPage").value=page;
	   	document.getElementById("formid").submit();
   	
   	}
   	
   }
   //末页
   function changepage2()
   {
   	var pages =  parseInt(document.getElementById("pages").value);
   	document.getElementById("currentPage").value=pages;
   	document.getElementById("formid").submit();
   }
   
   //跳转页
   function changepage3()
   {
   	var currentpage = document.getElementById("index").value;
   	document.getElementById("currentPage").value=currentpage;
   	document.getElementById("formid").submit();
   }
   
   function sortType(info)
   {
   
	   if(info == undefined) info = this;
	   var sort =info.getAttribute("sort");
	   
	   var type= info.getAttribute("type");
	   
	   
	   alert(sort+"------"+type)
	   if(type=="DESC")
	   {
	      info.setAttribute("type","ASC");
	      document.getElementById("type").value="ASC";
	   
	   }
	   if(type=="ASC")
	   {
	
	   	  info.setAttribute("type","DESC");
	      document.getElementById("type").value="DESC";
	   
	   }
	   document.getElementById("sort").value=sort;
	   document.getElementById("formid").submit();
	   
   }
   
   function doSearch()
   {
   
   	document.getElementById("currentPage").value=1;
   document.getElementById("formid").submit();
   }
   
   </script>
  </body>
</html>
